package net.sapfree.display.tags.person;

import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;

import net.sapfree.common.Constants;
import net.sapfree.core.db.DBConnectionProvider;
import net.sapfree.core.db.DataBaseExecutor;
import net.sapfree.core.db.Record;

public class FriendIndexTag extends TagSupport {
	private Record r=null;
	private Record rtemp = null;
	private String frienduuid = null;
	private static Logger log = Logger.getLogger(FriendIndexTag.class.getClass());
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public int doStartTag() throws JspException {
		Connection conn=null;
		try {
			conn = DBConnectionProvider.getConnection(Constants.JNDI_SAPFREE);
			
			FriendIndexListTag friendList = (FriendIndexListTag) pageContext.getAttribute("FriendIndexListTag");
			rtemp = (Record)friendList.getCurrent();
		
			String fuuid = rtemp.getString("FR_FRIENDUUID","");
			
			Record personrecord = new Record(conn,"PERSONINFO");
			personrecord.setPrimaryKey("PI_UUID");
			personrecord.addData("PI_UUID",fuuid);
			//根据用户的uuid，获取用户信息
			r = personrecord.findByPrimaryKey();
			
			r.addData("FRIENDCOUNT",rtemp.getString("FRIENDCOUNT","0"));
		} catch (SQLException e) {
			log.error("根据主键查找朋友时出错，",e);
		}finally{
			try{
				 conn.close();
			}catch(Exception e){}
		}
		pageContext.setAttribute("FriendIndexTag", this);
		return EVAL_BODY_INCLUDE;
	}
	
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}
 
	/**
	 * @return the artName
	 */
	public Record getRecord() {
		return r;
	}

	/**
	 * @param artName the artName to set
	 */
	public void setRecord(Record _r) {
		this.r = _r;;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}
	
	public String getFrienduuid(){
		return this.frienduuid;
	}
	public void setFrienduuid(String frienduuid){
		this.frienduuid = frienduuid;
	}
}
